package edu.ustb.aur.rightpackage;

import edu.ustb.aur.myenum.RightEnum;

import java.util.HashMap;

/**
 * @author bzs
 * 用户自定义权利的聚合 用户自定义的CustomizedRight
 */
public class OtherShip implements IShip {

    /**
     * 出租权
     */
    private RentalRight rentalRight;

    /**
     * 构造方法
     */
    public OtherShip() {
        this.rentalRight = new RentalRight();
    }

    /**
     * 带参构造函数
     */
    public OtherShip(RentalRight rentalRight) {
        this.rentalRight = rentalRight;
    }

    /**
     * 使用isSplitMap为每一个基本权利设置可分属性
     *
     * @param isSplitMap 权利枚举与是否可分的属性对应
     */
    @Override
    public void setEveyRightIsSplit(HashMap<RightEnum, Boolean> isSplitMap) {
        for (RightEnum rightEnum : isSplitMap.keySet()) {
            switch (rightEnum) {
                case RENTAL_RIGHT:
                    rentalRight.setIsSpilt(isSplitMap.get(rightEnum));
                    break;
                default:
                    break;
            }
        }
    }


    /** bzs
     *  做初始化，初始化可分属性，初始化权利列表
     */
    @Override
    public void init(HashMap<RightEnum, Boolean> isSplitMap, HashMap<RightEnum, AbstractRight> rightUserMap) {
        setEveyRightIsSplit(isSplitMap);
        initAllRightAndUser(rightUserMap);
    }

    /**
     * 初始化所有基本权利
     *
     * @param rightUserMap  一个权利对应多个用户占比 可能有多个用户  <right, <user, percent> >
     */
    public void initAllRightAndUser(HashMap<RightEnum, AbstractRight> rightUserMap) {
        for (RightEnum rightEnum : rightUserMap.keySet()) {
            for (String userAddress : rightUserMap.get(rightEnum).rightMap.keySet()) {
                rightUserMap.get(rightEnum).initRight(userAddress,rightUserMap.get(rightEnum).rightMap.get(userAddress));
            }
        }
    }

    public RentalRight getRentalRight() {
        return rentalRight;
    }
}
